package com.net.xpay.stat.task;

import com.net.common.util.SerializationUtil;
import com.net.xpay.common.domain.DailyTaskRecord;
import com.net.xpay.common.enums.systemTask.DailyTaskName;
import com.net.xpay.common.helper.NoticeHelper;
import com.net.xpay.common.service.DailyTaskService;
import com.net.xpay.common.service.PartnerCombinationSettleService;
import com.net.xpay.common.service.impl.AbstractDailyTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 合伙人佣金业务统一结算
 **/
@Service
@Slf4j
public class PartnerCombinationSettleDailyTask extends AbstractDailyTaskService implements DailyTaskService {

    @Autowired
    private PartnerCombinationSettleService partnerCombinationSettleService;

    @Autowired
    private NoticeHelper noticeHelper;


    @Override
    protected String getDailyTaskName() {
        return DailyTaskName.PARTNER_COMBINATION_SETTLE_RECORD;
    }

    @Override
    protected boolean doWorkByDayInternal(DailyTaskRecord record) {
        log.warn("start partnerCombinationSettleDailyTask|day={}", record.getDay());
        partnerCombinationSettleService.statPartnerCombinationSettleRecord(record.getDay(), record);
        log.warn("end partnerCombinationSettleDailyTask|day={}", record.getDay());
        if (record.getFailedCount() != 0L) {
            log.warn("doWorkByDayInternal failedCount != 0| record={}", SerializationUtil.obj2String(record));
            noticeHelper.sendSystemMonitorNotice("合伙人佣金业务统一结算异常：partnerCombinationSettleDailyTask failedCount != 0|recordId=" + record.getId(), "text");
            return false;
        }
        return true;
    }

    @Override
    protected int getFirstStartDayDiff() {
        return 7;
    }


}